﻿using System;

namespace Serious
{
    public static class MathExt
    {
        public const Single Epsilon = 1.0f / 32.0f;

        public static Single Sqrt(Single n)
        {
            return (Single)Math.Sqrt(n);
        }
        public static Single Sqr(Single n)
        {
            return n * n;
        }
        public static double Sqr(double n)
        {
            return n * n;
        }

        public static Single Cos(Single n)
        {
            return (Single)Math.Cos(n);
        }
        public static Single Sin(Single n)
        {
            return (Single)Math.Sin(n);
        }

        public static Single WrapAngleDeg(Single angle_deg)
        {
            return angle_deg % 360.0f;
        }

        public static Single Normalize(Single value, Single low, Single hi)
        {
            return (value - low) / (hi - low);
        }

        public static Single MoveValueToward(Single value, Single destination, Single rate)
        {
            Single delta = destination - value;
            int sign = Math.Sign(delta);
            Single deltaMag = sign * delta;
            if (deltaMag <= rate)
            {
                return destination;
            }
            else
            {
                return value += sign * rate;
            }
        }
    }
}
